
cmake_minimum_required(VERSION 3.14)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/outputs)

execute_process(
    COMMAND python -c "import tensorflow as tf; print(' '.join(tf.sysconfig.get_compile_flags()))"
    OUTPUT_VARIABLE TF_CFLAGS
    OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
    COMMAND python -c "import tensorflow as tf; print(' '.join(tf.sysconfig.get_link_flags()))"
    OUTPUT_VARIABLE TF_LFLAGS
    OUTPUT_STRIP_TRAILING_WHITESPACE
)

separate_arguments(TF_CFLAGS)
separate_arguments(TF_LFLAGS)
message(STATUS "TF_CFLAGS: ${TF_CFLAGS}")
message(STATUS "TF_LFLAGS: ${TF_LFLAGS}")

file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_LIST_DIR}/ops_and_kernels/*.cc)
add_library(custom_ops SHARED ${SOURCES})

target_compile_options(custom_ops PRIVATE ${TF_CFLAGS})
target_link_libraries(custom_ops PRIVATE ${TF_LFLAGS})